import request from "@/utils/request.ts";
import type {CategoryResponseData, AttrResponseData, Attr} from "@/api/product/attr/type.ts";

enum API {
    C1_URL = '/admin/product/getCategory1',
    C2_URL = '/admin/product/getCategory2/',
    C3_URL = '/admin/product/getCategory3/',
//     获取分类后的已有品牌属性标签
    ATTR_URL = '/admin/product/attrInfoList/',
    ADDORUPDATEATTR_URL = '/admin/product/saveAttrInfo/',
    DELETEATTR_URL = '/admin/product/deleteAttr/'
}

// 一级分类
export const reqC1 = () => {
    return request.get<any, CategoryResponseData>(API.C1_URL)
}

// 二级分类
export const reqC2 = (id:number|string) => {
    return request.get<any, CategoryResponseData>(API.C2_URL + id)
}

//三级分类
export const reqC3 = (id:number|string) => {
    return request.get<any, CategoryResponseData>(API.C3_URL + id)
}

//获取品牌属性
export const reqAttr = (category1Id:string|number,category2Id:string|number,category3Id:string|number) => {
    return request.get<any,AttrResponseData>(API.ATTR_URL + `${category1Id}/${category2Id}/${category3Id}`)
}

//添加或修改已有品牌的属性 
export const reqAddOrUpdateAttr = (data:Attr) => {
    return request.post<any, any>(API.ADDORUPDATEATTR_URL, data)
}

//删除已有品牌属性
export const reqDeleteAttr = (attrId:number) => {
    return request.delete<any, any>(API.DELETEATTR_URL + attrId)
}